﻿using MediatR.Core.Notification;
using MediatR.Core.Request;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MediatR.Core.Controller
{
    public class MyController
    {
        private readonly IMediator _mediator;

        public MyController(IMediator mediator)
        {
            _mediator = mediator;
        }

        public async Task<IActionResult> Get(string name)
        {
            var request = new MyRequest { Name = name };
            var response = await _mediator.Send(request);  // 发送请求并获取响应
            return null;
        }


        public async Task<IActionResult> Post( string message)
        {
            var notification = new MyNotification { Message = message };
            await _mediator.Publish(notification);  // 发布通知
            return null;
        }

    }
}
